﻿package mortal.game.view.fashion
{
    import Message.DB.Tables.*;
    import Message.Game.*;
    import Message.Public.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import extend.language.*;
    import mortal.component.gconst.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.manager.msgTip.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.view.palyer.data.*;
    import mortal.game.view.palyer.util.*;
    import mortal.game.view.palyer.view.*;
    import mortal.game.view.playerSystem.*;
    import mortal.game.view.shop.*;
    import mortal.mvc.core.*;

    public class FashionController extends PlayerBaseController
    {
        private var _tabData:PlayerTabData;
        private var _currentPanel:FashionPanelBase;
        public static var FashionType:int;

        public function FashionController()
        {
            return;
        }// end function

        override protected function initView() : GSprite
        {
            if (this._currentPanel == null && this._tabData)
            {
                this._currentPanel = UICompomentPool.getUICompoment(this._tabData.panelClass, GameController.playerSystem.view as Window);
                FashionController.FashionType = this._currentPanel.fashionType;
                this.updateFashionActivityWin();
            }
            return this._currentPanel;
        }// end function

        override protected function initServer() : void
        {
            Dispatcher.addEventListener(EventName.FashionOpenAdvanceWin, this.onOpenFashionAdvancePanel);
            Dispatcher.addEventListener(EventName.FashionUseFashionSkill, this.onUseFashionSkillBook);
            Dispatcher.addEventListener(EventName.FashionUseTalentGrowthProp, this.onUseGrowthTalentProp);
            NetDispatcher.addCmdListener(ServerCommand.SkillListUpdate, this.onSkillListUpdate);
            NetDispatcher.addCmdListener(ServerCommand.SkillAdd, this.onFashionSkillUpdate);
            NetDispatcher.addCmdListener(ServerCommand.SkillUpgrade, this.onFashionSkillUpdate);
            NetDispatcher.addCmdListener(ServerCommand.FashionActiveFashion, this.onOpenFashionHandler);
            NetDispatcher.addCmdListener(ServerCommand.FashionLevelUp, this.onFashionLevelUp);
            NetDispatcher.addCmdListener(ServerCommand.RebateDayChargeInfoBack, this.onRebateChargeHandler);
            Dispatcher.addEventListener(EventName.FashionShowHideShapCard, this.onShowHideShapCard);
            return;
        }// end function

        override public function removeWin() : void
        {
            super.removeWin();
            if (this._currentPanel)
            {
                this._currentPanel.dispose();
                this._currentPanel = null;
                _view = null;
                this._tabData = null;
            }
            if (FashionActivityWin.isViewShow)
            {
                FashionActivityWin.instance.hide();
            }
            if (ChargeActivityWin.isViewShow)
            {
                ChargeActivityWin.instance.hide();
            }
            return;
        }// end function

        private function onOpenFashionAdvancePanel(event:DataEvent) : void
        {
            var _loc_2:int = 0;
            var _loc_4:FashionAdvanceData = null;
            var _loc_5:ItemData = null;
            if (event.data is ItemData)
            {
                _loc_5 = event.data as ItemData;
                _loc_2 = _loc_5.itemInfo.type;
            }
            else if (event.data is int)
            {
                _loc_2 = event.data as int;
            }
            var _loc_3:* = Cache.instance.role.entityInfo.level;
            switch(_loc_2)
            {
                case EAdvanceType._EAdvanceTypeFashionClothesUp:
                case EAdvanceComponentType._EAdvanceComponentTypeClothes:
                {
                    if (_loc_3 < GameConst.ClothOpenLevel)
                    {
                        _loc_4 = Cache.instance.fashion.getFashionInfo(EFashionType._EFashionClothes);
                        if (_loc_4.advanceInfo && _loc_4.advanceInfo.state < 0)
                        {
                            MsgManager.showRollTipsMsg(Language.getStringByParam(41040, GameConst.ClothOpenLevel));
                            return;
                        }
                    }
                    Dispatcher.dispatchEvent(new DataEvent(EventName.PlayerModuleShowIndexByType, PlayerConst.TabType_Clothes));
                    break;
                }
                case EAdvanceType._EAdvanceTypeFashionWingUp:
                case EAdvanceComponentType._EAdvanceComponentTypeWing:
                {
                    if (_loc_3 < GameConst.WingOpenLevel)
                    {
                        _loc_4 = Cache.instance.fashion.getFashionInfo(EFashionType._EFashionWing);
                        if (_loc_4.advanceInfo && _loc_4.advanceInfo.state < 0)
                        {
                            MsgManager.showRollTipsMsg(Language.getStringByParam(41041, GameConst.WingOpenLevel));
                            return;
                        }
                    }
                    Dispatcher.dispatchEvent(new DataEvent(EventName.PlayerModuleShowIndexByType, PlayerConst.TabType_Wing));
                    break;
                }
                case EAdvanceType._EAdvanceTypeFashionWeaponUp:
                case EAdvanceComponentType._EAdvanceComponentTypeWeapon:
                {
                    if (_loc_3 < GameConst.ArtifactOpenLevel)
                    {
                        _loc_4 = Cache.instance.fashion.getFashionInfo(EFashionType._EFashionWeapon);
                        if (_loc_4.advanceInfo && _loc_4.advanceInfo.state < 0)
                        {
                            MsgManager.showRollTipsMsg(Language.getStringByParam(41042, GameConst.ArtifactOpenLevel));
                            return;
                        }
                    }
                    Dispatcher.dispatchEvent(new DataEvent(EventName.PlayerModuleShowIndexByType, PlayerConst.TabType_Artifact));
                    break;
                }
                case EAdvanceType._EAdvanceTypeFashionFightSoulUp:
                case EAdvanceComponentType._EAdvanceComponentTypeFightSoul:
                {
                    if (_loc_3 < GameConst.FightSoulOpenLevel)
                    {
                        _loc_4 = Cache.instance.fashion.getFashionInfo(EFashionType._EFashionFightSoul);
                        if (_loc_4.advanceInfo && _loc_4.advanceInfo.state < 0)
                        {
                            MsgManager.showRollTipsMsg(Language.getStringByParam(41043, GameConst.FightSoulOpenLevel));
                            return;
                        }
                    }
                    Dispatcher.dispatchEvent(new DataEvent(EventName.PlayerModuleShowIndexByType, PlayerConst.TabType_FightSoul));
                    break;
                }
                case EAdvanceType._EAdvanceTypeFashionFightMethodUp:
                case EAdvanceComponentType._EAdvanceComponentTypeFightMethod:
                {
                    if (_loc_3 < GameConst.FightMethodOpenLevel)
                    {
                        _loc_4 = Cache.instance.fashion.getFashionInfo(EFashionType._EFashionFightMethod);
                        if (_loc_4.advanceInfo && _loc_4.advanceInfo.state < 0)
                        {
                            MsgManager.showRollTipsMsg(Language.getStringByParam(41044, GameConst.FightMethodOpenLevel));
                            return;
                        }
                    }
                    Dispatcher.dispatchEvent(new DataEvent(EventName.PlayerModuleShowIndexByType, PlayerConst.TabType_FightMethod));
                    break;
                }
                case EAdvanceType._EAdvanceTypeFashionDragonSoulUp:
                case EAdvanceComponentType._EAdvanceComponentTypeDragonSoul:
                {
                    if (_loc_3 < GameConst.DragonSoulOpenLevel)
                    {
                        _loc_4 = Cache.instance.fashion.getFashionInfo(EFashionType._EFashionDragonSoul);
                        if (_loc_4.advanceInfo && _loc_4.advanceInfo.state < 0)
                        {
                            MsgManager.showRollTipsMsg(Language.getStringByParam(41045, GameConst.DragonSoulOpenLevel));
                            return;
                        }
                    }
                    Dispatcher.dispatchEvent(new DataEvent(EventName.PlayerModuleShowIndexByType, PlayerConst.TabType_DragonSoul));
                    break;
                }
                case EAdvanceType._EAdvanceTypeFashionHolyBookUp:
                case EAdvanceComponentType._EAdvanceComponentTypeHolyBook:
                {
                    if (_loc_3 < GameConst.HolyBookOpenLevel)
                    {
                        _loc_4 = Cache.instance.fashion.getFashionInfo(EAdvanceComponentType._EAdvanceComponentTypeHolyBook);
                        if (_loc_4.advanceInfo && _loc_4.advanceInfo.state < 0)
                        {
                            MsgManager.showRollTipsMsg(Language.getStringByParam(41046, GameConst.HolyBookOpenLevel));
                            return;
                        }
                    }
                    Dispatcher.dispatchEvent(new DataEvent(EventName.PlayerModuleShowIndexByType, PlayerConst.TabType_HolyBook));
                    break;
                }
                case EAdvanceType._EAdvanceTypeFashionWarShieldUp:
                case EAdvanceComponentType._EAdvanceComponentTypeWarShield:
                {
                    if (_loc_3 < GameConst.WarShieldOpenLevel)
                    {
                        _loc_4 = Cache.instance.fashion.getFashionInfo(EAdvanceComponentType._EAdvanceComponentTypeWarShield);
                        if (_loc_4.advanceInfo && _loc_4.advanceInfo.state < 0)
                        {
                            MsgManager.showRollTipsMsg(Language.getStringByParam(41047, GameConst.WarShieldOpenLevel));
                            return;
                        }
                    }
                    Dispatcher.dispatchEvent(new DataEvent(EventName.PlayerModuleShowIndexByType, PlayerConst.TabType_WarShield));
                    break;
                }
                case EAdvanceType._EAdvanceTypeFashionMonsterSoulUp:
                case EAdvanceComponentType._EAdvanceComponentTypeMonsterSoul:
                {
                    if (_loc_3 < GameConst.MonsterSoulOpenLevel)
                    {
                        _loc_4 = Cache.instance.fashion.getFashionInfo(EAdvanceComponentType._EAdvanceComponentTypeMonsterSoul);
                        if (_loc_4.advanceInfo && _loc_4.advanceInfo.state < 0)
                        {
                            MsgManager.showRollTipsMsg(Language.getStringByParam(41048, GameConst.MonsterSoulOpenLevel));
                            return;
                        }
                    }
                    Dispatcher.dispatchEvent(new DataEvent(EventName.PlayerModuleShowIndexByType, PlayerConst.TabType_MonsterSoul));
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        private function onUseFashionSkillBook(event:DataEvent) : void
        {
            var _loc_3:int = 0;
            var _loc_4:int = 0;
            var _loc_5:FashionAdvanceData = null;
            var _loc_2:* = event.data;
            if (_loc_2)
            {
                _loc_3 = _loc_2.skillType as int;
                _loc_4 = FashionUtil.getFashionTypeBySkillType(_loc_3);
                _loc_5 = Cache.instance.fashion.getFashionInfo(_loc_4);
                if (!_loc_5.advanceInfo || _loc_5.advanceInfo.state < 0)
                {
                    MsgManager.showRollTipsMsg(Language.getStringByParam(41049, FashionUtil.getFashionNameByType(_loc_4)), MsgRollTipsType.msgRollTips3);
                    return;
                }
                if (!FashionUtil.isSkillBookAvailable(_loc_2.itemData))
                {
                    return;
                }
                Dispatcher.dispatchEvent(new DataEvent(EventName.FashionOpenAdvanceWin, FashionUtil.getFashionTypeBySkillType(_loc_3)));
            }
            return;
        }// end function

        private function onSkillListUpdate(param1:Object) : void
        {
            Cache.instance.fashion.updateFashionSkill();
            return;
        }// end function

        private function onFashionSkillUpdate(param1:Object) : void
        {
            var _loc_4:int = 0;
            var _loc_2:* = param1 as SSkill;
            var _loc_3:* = SkillConfig.instance.getInfoById(_loc_2.skillId);
            if (_loc_3)
            {
                _loc_4 = GameDefConfig.instance.getOtherSkillTypeByPosType(_loc_3.posType);
                if (FashionUtil.isFashionSkill(_loc_4))
                {
                    Cache.instance.fashion.updateFashionSkill();
                    Dispatcher.dispatchEvent(new DataEvent(EventName.FashionUpdateFashionSkill));
                }
            }
            return;
        }// end function

        private function updateActivityWin() : void
        {
            var _loc_3:Boolean = false;
            var _loc_1:* = (this._currentPanel as FashionPanelBase).fashionType;
            var _loc_2:* = Cache.instance.fashion.getFashionInfo(_loc_1);
            if (_loc_2.advanceInfo)
            {
                _loc_3 = FashionUtil.isNeedReturnFashion(_loc_1);
                if (_loc_3 && _loc_2.advanceInfo.code < 3 && FashionActivityWin.instance.isHide)
                {
                    FashionActivityWin.instance.data = _loc_2;
                    FashionActivityWin.instance.show();
                    FashionActivityWin.instance.show(this.window.x + this.window.width + 5, this.window.y + 37);
                    FashionActivityWin.instance.layer.setTop(this.window);
                }
                else if (FashionActivityWin.hasInstance() && !FashionActivityWin.instance.isHide)
                {
                    if (_loc_2.advanceInfo.code >= 3 || !_loc_3)
                    {
                        FashionActivityWin.instance.hide();
                    }
                    else
                    {
                        FashionActivityWin.instance.data = _loc_2;
                    }
                }
            }
            return;
        }// end function

        private function onOpenFashionHandler(param1:Object) : void
        {
            var _loc_3:int = 0;
            var _loc_4:String = null;
            var _loc_2:* = param1 as SAttributeUpdate;
            if (_loc_2)
            {
                _loc_3 = int(_loc_2.valueStr);
                if (_loc_3 == EFashionType._EFashionClothes || _loc_3 == EFashionType._EFashionWing || _loc_3 == EFashionType._EFashionWeapon)
                {
                    if (_loc_2.value > 0)
                    {
                        switch(_loc_3)
                        {
                            case EFashionType._EFashionClothes:
                            {
                                _loc_4 = PlayerConst.TabType_Clothes;
                                break;
                            }
                            case EFashionType._EFashionWing:
                            {
                                _loc_4 = PlayerConst.TabType_Wing;
                                break;
                            }
                            case EFashionType._EFashionWeapon:
                            {
                                _loc_4 = PlayerConst.TabType_Artifact;
                                break;
                            }
                            case EAdvanceComponentType._EAdvanceComponentTypeHolyBook:
                            {
                                _loc_4 = PlayerConst.TabType_HolyBook;
                                break;
                            }
                            case EAdvanceComponentType._EAdvanceComponentTypeWarShield:
                            {
                                _loc_4 = PlayerConst.TabType_WarShield;
                                break;
                            }
                            case EAdvanceComponentType._EAdvanceComponentTypeMonsterSoul:
                            {
                                _loc_4 = PlayerConst.TabType_MonsterSoul;
                                break;
                            }
                            default:
                            {
                                break;
                            }
                        }
                        Dispatcher.dispatchEvent(new DataEvent(EventName.PlayerModuleShowIndexByType, _loc_4));
                    }
                }
            }
            return;
        }// end function

        private function onUseGrowthTalentProp(event:DataEvent) : void
        {
            var _loc_2:* = event.data as ItemData;
            var _loc_3:* = FashionUtil.getFashionTypeByProp(_loc_2);
            var _loc_4:* = Cache.instance.fashion.getFashionInfo(_loc_3);
            if (_loc_4.advanceInfo == null || _loc_4 && _loc_4.advanceInfo && _loc_4.advanceInfo.state < 0)
            {
                MsgManager.showRollTipsMsg(FashionUtil.getFashionNameByType(_loc_3) + Language.getString(41050));
                return;
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.FashionOpenAdvanceWin, _loc_3));
            return;
        }// end function

        public function set tabData(param1:PlayerTabData) : void
        {
            this._tabData = param1;
            return;
        }// end function

        public function getCurrFashionType() : int
        {
            var _loc_1:int = 0;
            switch(this._tabData.tabType)
            {
                case PlayerConst.TabType_Clothes:
                {
                    _loc_1 = EFashionType._EFashionClothes;
                    break;
                }
                case PlayerConst.TabType_Wing:
                {
                    _loc_1 = EFashionType._EFashionWing;
                    break;
                }
                case PlayerConst.TabType_Artifact:
                {
                    _loc_1 = EFashionType._EFashionWeapon;
                    break;
                }
                case PlayerConst.TabType_FightSoul:
                {
                    _loc_1 = EFashionType._EFashionFightSoul;
                    break;
                }
                case PlayerConst.TabType_FightMethod:
                {
                    _loc_1 = EFashionType._EFashionFightMethod;
                    break;
                }
                case PlayerConst.TabType_DragonSoul:
                {
                    _loc_1 = EFashionType._EFashionDragonSoul;
                    break;
                }
                case PlayerConst.TabType_HolyBook:
                {
                    _loc_1 = EAdvanceComponentType._EAdvanceComponentTypeHolyBook;
                    break;
                }
                case PlayerConst.TabType_WarShield:
                {
                    _loc_1 = EAdvanceComponentType._EAdvanceComponentTypeWarShield;
                    break;
                }
                case PlayerConst.TabType_MonsterSoul:
                {
                    _loc_1 = EAdvanceComponentType._EAdvanceComponentTypeMonsterSoul;
                    break;
                }
                default:
                {
                    break;
                }
            }
            return _loc_1;
        }// end function

        private function onFashionLevelUp(param1:Object) : void
        {
            this.updateFashionActivityWin();
            return;
        }// end function

        private function onRebateChargeHandler(param1:Object) : void
        {
            if (this._currentPanel && !this._currentPanel.isDisposed)
            {
                this.updateFashionActivityWin();
            }
            return;
        }// end function

        private function updateFashionActivityWin(param1:Object = null) : void
        {
            var _loc_2:TMountConfig = null;
            var _loc_3:ChargeActivityData = null;
            var _loc_4:* = this.getCurrFashionType();
            var _loc_5:* = Cache.instance.fashion.getFashionInfo(_loc_4);
            if (_loc_5.advanceInfo && _loc_5.advanceInfo.code < 3)
            {
                if (ClockManager.instance.serverOpenDateNum <= 7 && Cache.instance.openServerSevenDay.getTargetTypeName() == FashionUtil.getFashionNameByType(_loc_4) && Cache.instance.rebate.rechargeSum == 0)
                {
                    ChargeActivityWin.instance.show(window.x + window.width + 8, window.y);
                    ChargeActivityWin.instance.layer.setTop(this.window);
                    _loc_2 = MountConfig.instance.getMountInfoByCode(3, _loc_4);
                    _loc_3 = new ChargeActivityData();
                    _loc_3.activityType = ChargeActivityData.ActivityType_Three;
                    _loc_3.tmount = _loc_2;
                    ChargeActivityWin.instance.data = _loc_3;
                    if (FashionActivityWin.isViewShow)
                    {
                        FashionActivityWin.instance.hide();
                    }
                }
                else
                {
                    this.updateActivityWin();
                    if (ChargeActivityWin.isViewShow)
                    {
                        ChargeActivityWin.instance.hide();
                    }
                }
            }
            else if (_loc_5.advanceInfo && _loc_5.advanceInfo.code == 3)
            {
                if (FashionActivityWin.isViewShow)
                {
                    FashionActivityWin.instance.hide();
                }
                if (ClockManager.instance.serverOpenDateNum <= 7 && Cache.instance.openServerSevenDay.getTargetTypeName() == FashionUtil.getFashionNameByType(_loc_4) && Cache.instance.rebate.rechargeSum < 500)
                {
                    ChargeActivityWin.instance.show(window.x + window.width + 8, window.y);
                    ChargeActivityWin.instance.layer.setTop(this.window);
                    _loc_2 = MountConfig.instance.getMountInfoByCode(4, _loc_4);
                    _loc_3 = new ChargeActivityData();
                    _loc_3.activityType = ChargeActivityData.ActivityType_Four;
                    _loc_3.tmount = _loc_2;
                    ChargeActivityWin.instance.data = _loc_3;
                }
            }
            if (BuyGiftItemWin.isViewShow)
            {
                BuyGiftItemWin.instance.layer.setTop(BuyGiftItemWin.instance);
            }
            return;
        }// end function

        private function onShowHideShapCard(event:DataEvent) : void
        {
            var _loc_2:* = event.data as int;
            GameProxy.fashion.changeShapeCard(_loc_2);
            return;
        }// end function

    }
}
